ClassTemplate = {}
ClassTemplate.mt = { __index = ClassTemplate }


function ClassTemplate:generate( name, parent, output )

	local insert, prefix

	local out = SRX_PROJECT_DIR..output
	local par_s


	if not parent then parent = name; insert = ""; prefix = "" else
	par_s = self:cc_to_( parent )

	insert = [[

	self = ]] .. parent .. [[:new()
]];

	prefix = "\n" .. parent..[[ = require']]..par_s..[['

]];

	end




	local s =

	prefix .. name .. [[ = {}
]] .. name .. [[.mt = { __index = ]] .. name .. [[ }
setmetatable(]] .. name .. [[, ]] .. parent .. [[.mt)

function ]] .. name .. [[:initialize()

]] .. insert .. [[


end


function ]] .. name ..[[:new()

	self:initialize()

	return self

end



return ]]..name;

	file = assert(io.open(out, "w"))
	file:write(s)
	file:close()

	print(" document created ")



end


function ClassTemplate:cc_to_( text )

	local nt = text:gsub("^(%u)(%w+)(%u)(%w+)$",

		function(c1, b1, c2, b2)

			c1 = c1:lower()
			c2 = c2:lower()
			local s = c1..b1.."_"..c2..b2

			return s

		end )

	if nt == text then nt = nt:lower() end

	return nt

end





return ClassTemplate
